package com.nd.controller.admin;


import com.nd.pojo.bean.Topic;
import com.nd.pojo.bo.CouponDeleteBo;
import com.nd.pojo.bo.TopicQueryBo;
import com.nd.pojo.vo.AdQueryDataVo;
import com.nd.pojo.vo.BaseRespVo;
import com.nd.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.Service;

@RestController
@RequestMapping("admin/topic")
public class TopicController {

    @Autowired
    TopicService topicService;

    @RequestMapping("list")
    public BaseRespVo query (TopicQueryBo topicQueryBo){

        AdQueryDataVo topicQueryDataVo = topicService.queryAll(topicQueryBo.getPage(), topicQueryBo.getLimit(), topicQueryBo.getSort(),
                topicQueryBo.getOrder(), topicQueryBo.getTitle(), topicQueryBo.getSubtitle());


        return BaseRespVo.ok(topicQueryDataVo);
    }


    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Topic topic){

        Integer code = topicService.delete(topic.getId());

        if (code == 1) {
            return BaseRespVo.ok();
        }

        return BaseRespVo.fail();
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Topic topic){

        Topic topic1 = topicService.create(topic);

        return BaseRespVo.ok(topic1);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Topic topic){

        Topic topic1 = topicService.update(topic);

        return BaseRespVo.ok(topic1);
    }
}
